const mongoose = require('mongoose')

const url = 'mongodb://localhost:27017';
const dbName = 'myblogs';

// mongoose.set('useCreateIndex', true)

mongoose.connect(`${url}/${dbName}`, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useCreateIndex: true
})

const db = mongoose.connection;

db.on('error', (err) => {
  console.log('err', err)
})

db.once('open', () => {
  console.log('success')
})

module.exports = mongoose;
